package by.amakarevich.webapp.page.booking.user;

import java.util.List;

import javax.inject.Inject;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.ResourceModel;

import by.amakarevich.datamodel.Booking;
import by.amakarevich.datamodel.UserAccount;
import by.amakarevich.services.BookingService;
import by.amakarevich.webapp.app.BasicAuthenticationSession;
import by.amakarevich.webapp.page.AlternativeBaseLayout;
import by.amakarevich.webapp.page.thread.dmc.DMCThreadPage;

public class UserBookingPage extends AlternativeBaseLayout {
	
	@Inject
	private BookingService bookingService;
	
	UserAccount user = BasicAuthenticationSession.get().getUser();
	private Boolean payStatus;
	private Boolean canceled;
	
	public UserBookingPage(Boolean payStatus, Boolean canceled ){
		this.payStatus=payStatus;
		this.canceled=canceled;
	}
	
	@Override
	protected void onInitialize() {
		super.onInitialize();
		
		final List<Booking> allBookingByUser = bookingService.getAllBookingByUser(user, payStatus,canceled);
		
		
		add(new ListView<Booking>("details-panel",allBookingByUser) {
			@Override
			protected void populateItem(ListItem<Booking> item) {
				Booking booking = item.getModelObject();
				item.add((new UserBookingPanel("user-booking-panel", booking)));

			}
		});
		
		add(new Link("not-complited-booking-link") {
			@Override
			protected void onConfigure() {
				super.onConfigure();
				setVisible(payStatus||canceled);
			}
			
			@Override
			public void onClick() {
				setResponsePage(new UserBookingPage(false, false));
			}
		});
		
		add(new Link("complited-booking-link") {
			@Override
			protected void onConfigure() {
				super.onConfigure();
				setVisible(!(payStatus));
			}
			
			@Override
			public void onClick() {
				setResponsePage(new UserBookingPage(true, false));
			}
		});
		
		add(new Link("canceled-booking-link") {
			@Override
			protected void onConfigure() {
				super.onConfigure();
				setVisible(!(canceled));
			}
			
			@Override
			public void onClick() {
				setResponsePage(new UserBookingPage(false, true));
			}
		});
		
	}
	
	@Override
	protected IModel<String> getPageTitle() {
		return new ResourceModel("p.booking.title");
	}
	
			
		
}
